package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import entity.Depart;
import util.DbUtil;

public class DepartDao {

	public void save(Depart depart) {

	}

	public void update(Depart depart) {

	}


	public void delete(String id) {

	}
	
	public Depart findById(String id) {
		return null;
	}
	
	public List<Depart> findAll() {
		List<Depart> departs = new ArrayList<Depart>();
		try{
			Connection conn=DbUtil.getConn();
			String sql = "select * from t_dept";
			PreparedStatement ps = conn.prepareStatement(sql);
			ResultSet rs=ps.executeQuery();
			
			while(rs.next()){
				Depart depart=new Depart();
				depart.setId(rs.getString(1));
				depart.setName(rs.getString(2));
				departs.add(depart);
			}
			
			rs.close();
			
			ps.close();
			
		}catch(Exception e){
			e.printStackTrace();
		}
		return departs;
	}
	
}
